<template>
	<view class="tabs">
		<view class="container">
			<view
				v-for="(item, index) in list"
				:key="index"
				class="item"
				:class="index==active?'active':''"
				:style="{width: 100/list.length+'%'}"
				@click="tabClick(index)"
			>
				{{item}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: { // 传值
				type: Array,
				default: ()=> {
					return ['趋势', '明细']
				}
			}
		},
		data() {
			return {
				active: 0
			};
		},
		methods: {
			tabClick(i) {
				this.active = i;
				this.$emit('tabClick', i)
			}
		}
	}
</script>

<style lang="scss">
	.tabs {
		padding: $uni-spacing-30+$uni-spacing-4 $uni-spacing-30 - $uni-spacing-4;
		background-color: $uni-color-blue;
		.container {
			display: flex;
			justify-content: space-around;
			border: 1px solid $uni-color-white;
			border-radius: $uni-border-radius-md;
			.item {
				padding: $uni-spacing-10+$uni-spacing-3 0;
				color: $uni-color-white;
				text-align: center;
				border-right: 1px solid $uni-color-white;
				&:last-child {
					border-right: none;
				}
				&.active {
					color: $uni-color-blue;
					background-color: $uni-color-white;
				}
			}
		}
	}
</style>
